{% extends "base.html" %}
{% from "macros/widgets.html" import module_icon %}

{% block content %}
<div class="jumbotron">
  <div class="container">
    <h1>{{ dojo.name or dojo.id }}</h1>
  </div>
</div>
<div class="container">
  {% include "components/errors.html" %}
  {% if dojo_user.type == "admin" or user.type == "admin" %}
  <div class="col-lg-auto m-3">
    <figure>
      <a class="text-decoration-none" href="{{ url_for('pwncollege_dojos.view_dojo_admin', dojo=dojo.reference_id) }}">
        <i class="fas fa-users-cog fa-3x"></i>
        <figcaption><b style="font-family: 'Courier New', Courier, monospace">管理员</b></figcaption>
      </a>
    </figure>
  </div>
  {% endif %}
  
  <br>

  <h2 class="row">道馆简介</h2>
  <div class="row">
  {% if dojo.description %}
  <p>{{ dojo.description | markdown }}</p>
  <br>
  {% endif %}
  </div>
  <div class="row text-center">
    {% if dojo.course and user %}
    <div class="col-lg-auto m-3">
      <figure>
        <a class="text-decoration-none" href="{{ url_for('course.view_course', dojo=dojo.reference_id) }}">
          <i class="fas fa-graduation-cap fa-3x"></i>
          <figcaption><b style="font-family: 'Courier New', Courier, monospace">课程</b></figcaption>
        </a>
      </figure>
    </div>
    {% endif %}

  </div>

  <br>

  {% if dojo.award and dojo.award.get("emoji") %}
  {% set emoji = dojo.award["emoji"] %}
  <h2 class="row">道馆奖项</h2>
  <img style="width: 120px; margin: 24px 0;" src="/themes/dojo_theme/static/img/dojo/{{ emoji }}.svg">
  <br>
  {% endif %}

  {% if dojo.modules %}
  <h2 class="row">道馆状态</h2>
  <br>
  <div class="row">
    <p>
      <b>目前解决:</b> <code>{{ stats["active"] }}</code>
      <br>
      <b>黑客:</b> <code>{{ stats["users"] }}</code>
      <br>
      <b>关卡:</b> <code>{{ stats["challenges"] }}</code>
      <br>
      <b>解决方案:</b> <code>{{ stats["solves"] }}</code>
    </p>
  </div>

  <br>

  <h2 class="row">道馆模块</h2>
  <br>
  <ul class="card-list">
    {% for module in dojo.modules %}
    <a class="text-decoration-none" href="{{ url_for('pwncollege_dojo.view_module', dojo=dojo_id, module=module.id) }}">
      {# TODO: card-active, card-hidden #}
      <li class="card card-small">
        <div class="card-body">
          <h4 class="card-title">{{ module.name or module.id }}</h4>
            {% if module.data.icon %}
              {{ module_icon(icon="/themes/dojo_theme/static/img/dojo/{}.svg".format(module.data.icon) if (module.data.icon) else None) }}  
            {% endif %}
          <p class="card-text">
            {{ module.solves(user=user, ignore_visibility=True, ignore_admins=False).count() if user else 0 }} / {{ module.visible_challenges() | length }}
          </p>
        </div>
      </li>
    </a>
    {% endfor %}
  </ul>

  <br>

  <h2 class="row">道馆排名</h2>
  <br>
  {% from "macros/scoreboard.html" import scoreboard %}
  {{ scoreboard() }}

  {% endif %}
</div>
{% endblock %}

{% block scripts %}
<script defer onload="loadScoreboard(0, 1);" src="{{ url_for('views.themes', path='js/dojo/scoreboard.js') }}"></script>
<script defer src="{{ url_for('views.themes', path='js/dojo/copy.js') }}"></script>
{% endblock %}
